RAIS  3.2
C:/Projekte/RAIS/Specific Masks/EditFunctionalRoles_New_Update1.aspx.cs
Go to the documentation of this file.
00001 
00028 using System;
00029 using System.Data;
00030 using System.Configuration;
00031 using System.Collections;
00032 using System.Collections.Generic;
00033 using System.Web;
00034 using System.Web.Security;
00035 using System.Web.UI;
00036 using System.Web.UI.WebControls;
00037 using System.Web.UI.WebControls.WebParts;
00038 using System.Web.UI.HtmlControls;
00039 
00040 using RAIS.Common.DynamicMaskManagement;
00041 using RAIS.Common.UserManagement;
00042 
00043 using DataRoles = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.DataRole>;
00044 using DataRoleAttributes = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.DataRoleAttribute>;
00045 using FunctionRoles = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.FunctionRole>;
00046 using FunctionRoleCategories = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.FunctionRole.Category>;
00047 using FunctionRoleSubcategories = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.FunctionRole.Subcategory>;
00048 using Masks = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.Mask>;
00049 using FunctionRoleAttributes = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.FunctionRoleAttribute>;
00050 using UserTypes = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.UserTypeData>;
00051 
00052 namespace RAIS.UI.SpecificMasks
00053 {
00057     public partial class EditFunctionalRoles_New_Update1 : System.Web.UI.Page
00058     {
00062         enum EditFunctionalRoles_PageMode
00063         {
00064             viewRoles,
00065             addRole,
00066             editRole
00067         };
00068         string[] accessNames = new string[4];
00069                 //*********************************************************************
00070                 #region Event handlers
00071         protected void Page_PreLoad(object sender, EventArgs e)
00072         {
00073             RAIS.UI.Common.PageManagement.TrimTextBoxValues(this);
00074         }
00085         protected void Page_Load(object sender, EventArgs e)
00086         {
00087                         this.Response.Cache.SetNoStore();
00088                         if (this.CurrentUser == null)
00089                 UI.Common.AccessManagement.SignOut(this);
00090                         this.LBLresult.Text = string.Empty;
00091 
00092             if (!this.IsPostBack)
00093             {
00094                 this.BTNdelete.Attributes.Add("onclick", string.Format("javascript: return confirm('{0}');", RAIS.Common.Messages.DELETE_QUESTION_FUNCTIONAL_ROLE.Replace("'", "\\'")));
00095                 this.LBLusernameNoTranslation.Text = this.CurrentUser.Name;
00096 
00097                                 this.InitializeControls();
00098 
00099                 this.CurrentEditFunctionalRoles_PageMode = EditFunctionalRoles_PageMode.viewRoles;
00100 
00101                 UI.Common.PageManagement.InitializePage(this, this.TreeView1);
00102 //                              this.LBTNmessagebox.Visible = !(this.CurrentUser.FunctionalRole.Type == FunctionRole.FunctionRoleType.Guest);
00103                                 this.ShowRole();
00104             }
00105             UI.Common.PageManagement.InitHelpMainMenu(LBTNdefault);
00106         }
00107         protected void Page_Init(object sender, EventArgs e)
00108         {
00109             Common.PageManagement.SetScrolableListBox(LBfmrolename, this, true);
00110         }
00121         protected void LBfmrolename_SelectedIndexChanged(object sender, EventArgs e)
00122         {
00123                         this.SavedFunctionRoleSelection = this.LBfmrolename.SelectedValue;
00124                         this.EnableDisableEditDelete();
00125             this.ShowRole();
00126         }
00133         protected void BTNadd_Click(object sender, EventArgs e)
00134         {
00135             this.ClearRoleData();
00136             this.CreateTemporaryRole();
00137             this.Modified = true;
00138             this.CurrentEditFunctionalRoles_PageMode = EditFunctionalRoles_PageMode.addRole;
00139         }
00147         protected void BTNedit_Click(object sender, EventArgs e)
00148         {
00149                         this.Modified = true;
00150                         this.CurrentEditFunctionalRoles_PageMode = EditFunctionalRoles_PageMode.editRole;
00151         }
00158         protected void BTNdelete_Click(object sender, EventArgs e)
00159         {
00160             this.DeleteSelectedRole();
00161             this.EnableDisableEditDelete();
00162             this.ShowRole();
00163         }
00171                 protected void BTNsave_Click(object sender, EventArgs e)
00172                 {
00173                         if (this.CurrentEditFunctionalRoles_PageMode == EditFunctionalRoles_PageMode.addRole)
00174                         {
00175                                 this.AddNewRole();
00176                         }
00177                         else
00178                         {
00179                                 this.GetFunctionRoleFromMaskControls();
00180                                 this.SaveRole();
00181                         }
00182                         this.ShowRole();
00183                         //this.EnableDisableEditDelete();
00184                 }
00192         protected void BTNdiscard_Click(object sender, EventArgs e)
00193         {
00194             this.ClearRoleData();
00195             this.ShowRole();
00196 
00197             this.CurrentEditFunctionalRoles_PageMode = EditFunctionalRoles_PageMode.viewRoles;
00198             this.Modified = false;
00199 
00200             this.InitializeControls();
00201             this.EnableDisableControls();
00202         }
00209         protected void DDLvalidation_SelectedIndexChanged(object sender, EventArgs e)
00210         {
00211             this.SetNewValidationSelection(this.DDLvalidation.SelectedValue);
00212             this.Modified = true;
00213             this.EnableDisableControls();
00214         }
00221         protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
00222         {
00223             UI.Common.UserManagement.ProcessTreeViewOnRedirect(this.TreeView1);
00224         }
00231                 protected void LBTNlogout_Click(object sender, EventArgs e)
00232                 {
00233                         UI.Common.AccessManagement.SignOut(this);
00234                 }
00235                 #endregion
00236                 //*********************************************************************
00237                 #region Private helper methods
00238 
00244         void ShowRole()
00245         {
00246             if (this.SelectedRole == null)
00247             {
00248                 ClearRoleData();
00249                 return;
00250             }
00251             else
00252             {
00253                 this.TXTrolename.Text = this.SelectedRole.Name;
00254                 this.InitializaValidationSelection(this.SelectedRole);
00255 
00256                                 // Get protector
00257                                 Protector protector =
00258                                         ApplicationLogicLayer.DynamicMaskManagement.GetProtector(
00259                                                   "Functional Role"
00260                                                 , this.SelectedRole.ID);
00261                                 
00262                                 // Defend functional role with protector
00263                                 if (protector != null)
00264                                 {
00265                     //this.BTNedit.Attributes.Add("onclick", string.Format("javascript: return confirm('{0}');", protector.RenameMessage.Replace("'", "\\'")));
00266                     this.BTNedit.Attributes.Add("onclick", string.Format("javascript: alert('{0}'); return false;", protector.RenameMessage.Replace("'", "\\'")));
00267                     this.BTNdelete.Attributes.Add("onclick", string.Format("javascript: alert('{0}'); return false;", protector.DeleteMessage.Replace("'", "\\'")));
00268                                 }
00269                                 else
00270                                 {
00271                                         this.BTNedit.Attributes.Remove("onclick");
00272                     this.BTNdelete.Attributes.Add("onclick", string.Format("javascript: return confirm('{0}');", RAIS.Common.Messages.DELETE_QUESTION.Replace("'", "\\'")));
00273                                 }
00274                         }
00275         }
00279         void ClearRoleData()
00280         {
00281             this.TXTrolename.Text = string.Empty;
00282             this.DDLvalidation.SelectedIndex = 0;
00283         }
00287         private void DeleteSelectedRole()
00288         {
00289             FunctionRole selectedRole = this.SelectedRole;
00290 
00291             if (selectedRole != null)
00292             {
00293                 string returnMessage = string.Empty;
00294 
00295                 bool success = ApplicationLogicLayer.UserManagement.RemoveFunctionRole(selectedRole, ref returnMessage);
00296                 this.Session[RAIS.UI.Common.Constants.FUNCTION_ROLES_TAG] = null; //for resetting
00297                                 
00298                                 this.SavedFunctionRoleSelection = (this.LBfmrolename.SelectedIndex == 0)
00299                                         ? string.Empty
00300                                         : this.LBfmrolename.Items[this.LBfmrolename.SelectedIndex - 1].Value;
00301                                 UI.Common.UserManagement.InitializeFunctionalRolesListBox(this.LBfmrolename, this.SavedFunctionRoleSelection);
00302                 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult,
00303                                                                     returnMessage,
00304                                                                     success);
00305             }
00306         }
00310         private void CreateTemporaryRole()
00311         {
00312             FunctionRole tempRole = new FunctionRole();
00313             this.Session[UI.Common.Constants.FUNCTION_ROLE_TEMPORARY_TAG] = tempRole;
00314         }
00319         private bool ConfirmRoleDeletion()
00320         {
00321             return true;
00322         }
00327                 private bool AddNewRole()
00328                 {
00329                         string validationMessage = string.Empty;
00330                         bool success = this.ValidateNewFuncitonalRole(this.TXTrolename.Text, ref validationMessage);
00331 
00332                         if (success)
00333                         {
00334                 success = ApplicationLogicLayer.UserManagement.AddFunctionRole(this.TXTrolename.Text, FunctionRole.ValidationTypeNamesDictionary[this.DDLvalidation.SelectedValue], ref validationMessage);
00335                                 if (success)
00336                                 {
00337                                         FunctionRole tempRole = this.SelectedRole;
00338                                         this.Session[RAIS.UI.Common.Constants.FUNCTION_ROLE_TEMPORARY_TAG] = null;
00339                                         UI.Common.UserManagement.InitializeFunctionalRoles(this);
00340 
00341                                         FunctionRoles functionRoles = (FunctionRoles)this.Session[RAIS.UI.Common.Constants.FUNCTION_ROLES_TAG];
00342                                         FunctionRole savedRole = functionRoles[this.TXTrolename.Text];
00343 
00344                                         foreach (FunctionRoleAttribute attribute in tempRole.AddedAttributes.Values)
00345                                         {
00346                                                 success = savedRole.AddAttribute(attribute, ref validationMessage);
00347                                                 if (!success)
00348                                                         break;
00349                                         }
00350                                 }
00351 
00352                                 if (success)
00353                                 {
00354                                         this.CurrentEditFunctionalRoles_PageMode = EditFunctionalRoles_PageMode.viewRoles;
00355                                         this.Modified = false;
00356 
00357                                         this.SavedFunctionRoleSelection = this.TXTrolename.Text;
00358                                         this.InitializeControls();
00359                                         this.EnableDisableControls();
00360                                 }
00361                         }
00362                         RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult,
00363                                                                                                                                 validationMessage,
00364                                                                                                                                 success);
00365                         return success;
00366                 }
00371         private bool SaveRole()
00372         {
00373             string returnMessage = string.Empty;
00374             bool success = true;
00375 
00376             if (!this.Modified)
00377             {
00378                 returnMessage = RAIS.Common.Messages.FUNCTION_ROLE_NO_MODIFICATION;
00379                 success = false;
00380             }
00381             else
00382             {
00383                 success = ApplicationLogicLayer.UserManagement.SaveFunctionRole(this.SelectedRole, ref returnMessage);
00384                 if (success)
00385                 {
00386                     this.CurrentEditFunctionalRoles_PageMode = EditFunctionalRoles_PageMode.viewRoles;
00387                     this.Modified = false;
00388 
00389                                         this.SavedFunctionRoleSelection = this.TXTrolename.Text;
00390                     this.InitializeControls();
00391                     this.EnableDisableControls();
00392                 }
00393             }
00394             EnableDisableEditDelete();
00395             RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult,
00396                                                                 returnMessage,
00397                                                                 success);
00398             return success;
00399         }
00408         bool ValidateNewFuncitonalRole(string roleName, ref string returnMessage)
00409         {
00410             FunctionRoles funcitonRoles = (FunctionRoles)this.Session[UI.Common.Constants.FUNCTION_ROLES_TAG];
00411             if (funcitonRoles.ContainsKey(roleName))
00412             {
00413                 returnMessage = RAIS.Common.Messages.FUNCTION_ROLE_EXISTS;
00414                 return false;
00415             }
00416             else
00417             if (roleName.Length == 0)
00418             {
00419                 returnMessage = RAIS.Common.Messages.NAME_IS_EMTPY;
00420                 return false;
00421             }
00422             else
00423                 return true;
00424         }
00430         private bool SetNewValidationSelection(string newValidation)
00431         {
00432             FunctionRole.ValidationType newSelection = FunctionRole.ValidationTypeNamesDictionary[newValidation];
00433             FunctionRole selectedRole = this.SelectedRole;
00434             if (selectedRole != null)
00435             {
00436                 selectedRole.Validation = newSelection;
00437                 this.EnableDisableControls();
00438 
00439                 string returnMessage = RAIS.Common.Messages.MODIFICATION_PRESS_SAVE;
00440 
00441                 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult,
00442                                                                     returnMessage,
00443                                                                     true);
00444 
00445             }
00446             return false;
00447         }
00451         private void InitializaValidationSelection(FunctionRole functionalRole)
00452         {
00453             if (functionalRole != null)
00454             {
00455                 this.DDLvalidation.SelectedValue = functionalRole.ValidationData.VisibleName;
00456             }
00457         }
00461         private void InitializeControls()
00462         {
00463             UI.Common.UserManagement.InitializeFunctionalRolesListBox(this.LBfmrolename, this.SavedFunctionRoleSelection);
00464             UI.Common.UserManagement.InitializeValidationList(this.DDLvalidation);
00465         }
00469                 private void GetFunctionRoleFromMaskControls()
00470                 {
00471                         if (this.SelectedRole != null)
00472                         {
00473                                 this.SelectedRole.Name = TXTrolename.Text;
00474                         }
00475                 }
00479         private void EnableDisableControls()
00480         {
00481             this.LBfmrolename.Enabled = this.CurrentEditFunctionalRoles_PageMode == EditFunctionalRoles_PageMode.viewRoles;
00482 
00483             this.DDLvalidation.Enabled = this.CurrentEditFunctionalRoles_PageMode != EditFunctionalRoles_PageMode.viewRoles;
00484 
00485                         this.LBfma.Enabled = this.CurrentEditFunctionalRoles_PageMode == EditFunctionalRoles_PageMode.viewRoles;
00486             this.BTNadd.Enabled  = this.CurrentEditFunctionalRoles_PageMode == EditFunctionalRoles_PageMode.viewRoles;
00487             this.BTNsave.Enabled = this.Modified;
00488             this.BTNdiscard.Enabled = this.CurrentEditFunctionalRoles_PageMode != EditFunctionalRoles_PageMode.viewRoles;
00489 
00490             this.EnableDisableEditDelete();
00491 
00492             this.TXTrolename.Enabled = !(this.CurrentEditFunctionalRoles_PageMode == EditFunctionalRoles_PageMode.viewRoles);
00493 
00494             UI.Common.UserManagement.EnableCommonControls(this, this.CurrentEditFunctionalRoles_PageMode == EditFunctionalRoles_PageMode.viewRoles);
00495 
00496             this.LBLadmin.ForeColor = RAIS.UI.Common.Constants.COLOR_OF_MENU_BAR_TEXT_HIGHLIGHT;
00497 
00498             if( this.Modified )
00499                 this.BTNdiscard.Attributes.Add("onclick", string.Format("javascript: return confirm('{0}');", RAIS.Common.Messages.DISCARD_QUESTION_ROLE));
00500             else
00501                 this.BTNdiscard.Attributes.Remove("onclick");
00502 
00503                         if (this.CurrentEditFunctionalRoles_PageMode == EditFunctionalRoles_PageMode.viewRoles)
00504                                 this.SetFocus(this.LBfmrolename);
00505                         else
00506                                 this.SetFocus(this.TXTrolename);
00507                 }
00511         void EnableDisableEditDelete()
00512         {
00513             this.BTNedit.Enabled = this.CurrentEditFunctionalRoles_PageMode == EditFunctionalRoles_PageMode.viewRoles && this.SelectedRole != null;
00514             this.BTNdelete.Enabled = this.CurrentEditFunctionalRoles_PageMode == EditFunctionalRoles_PageMode.viewRoles && this.SelectedRole != null;
00515         }
00516         #endregion
00517                 //*********************************************************************
00518                 #region Private helper properties
00519 
00522         private FunctionRole SelectedRole
00523         {
00524             get
00525             {
00526                 if (this.Session[RAIS.UI.Common.Constants.FUNCTION_ROLE_TEMPORARY_TAG] != null)
00527                     return (FunctionRole)this.Session[RAIS.UI.Common.Constants.FUNCTION_ROLE_TEMPORARY_TAG];
00528                 else
00529                 {
00530                     FunctionRoles functionRoles = (FunctionRoles)this.Session[RAIS.UI.Common.Constants.FUNCTION_ROLES_TAG];
00531                     if (functionRoles != null && functionRoles.ContainsKey(this.LBfmrolename.SelectedValue))
00532                         return functionRoles[this.LBfmrolename.SelectedValue];
00533                     else
00534                         return null;
00535                 }
00536             }
00537         }
00541         EditFunctionalRoles_PageMode CurrentEditFunctionalRoles_PageMode
00542         {
00543             get
00544             {
00545                 if (this.Session[UI.Common.Constants.FUNCTION_ROLE_EDIT_MODE_TAG] != null)
00546                 {
00547                     return (EditFunctionalRoles_PageMode)this.Session[UI.Common.Constants.FUNCTION_ROLE_EDIT_MODE_TAG];
00548                 }
00549                 else
00550                     return EditFunctionalRoles_PageMode.viewRoles;
00551             }
00552             set
00553             {
00554                 string message;
00555                 switch (value)
00556                 {
00557                     case EditFunctionalRoles_PageMode.addRole: message = RAIS.UI.Common.Constants.ADDING_NEW_FUNCTIONAL_ROLE; break;
00558                     case EditFunctionalRoles_PageMode.editRole: message = RAIS.UI.Common.Constants.EDITTING_EXISTING_FUNCTIONAL_ROLE; break;
00559 
00560                     default:
00561                         this.Session[RAIS.UI.Common.Constants.FUNCTION_ROLE_TEMPORARY_TAG] = null;
00562                         message = string.Empty; 
00563                         break;
00564                 }
00565                 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult, message, true);
00566                 this.Session[UI.Common.Constants.FUNCTION_ROLE_EDIT_MODE_TAG] = value;
00567                 this.EnableDisableControls();
00568             }
00569         }
00573         bool Modified
00574         {
00575             get
00576             {
00577                 if (this.SelectedRole != null)
00578                     return this.SelectedRole.Modified;
00579                 else
00580                     return false;
00581             }
00582             set
00583             {
00584                 if (this.SelectedRole != null)
00585                     this.SelectedRole.Modified = value;
00586 
00587                 if (!value)
00588                 {
00589                     this.Session[RAIS.UI.Common.Constants.FUNCTION_ROLES_TAG] = null;
00590                 }
00591             }
00592         }
00596         protected UserData CurrentUser
00597         {
00598             get { return (UserData)this.Session[UI.Common.Constants.CURRENT_USER_TAG]; }
00599         }
00603                 private string SavedFunctionRoleSelection
00604                 {
00605                         get
00606                         {
00607                                 if (this.Session[RAIS.UI.Common.Constants.FUNCTION_ROLE_SAVED_SELECTION_TAG] != null)
00608                                         return this.Session[RAIS.UI.Common.Constants.FUNCTION_ROLE_SAVED_SELECTION_TAG].ToString();
00609                                 else
00610                                         return string.Empty;
00611                         }
00612                         set
00613                         {
00614                                 this.Session[RAIS.UI.Common.Constants.FUNCTION_ROLE_SAVED_SELECTION_TAG] = value;
00615                         }
00616                 }
00617                 #endregion
00618     }
00619 }